package com.sh.data.engine.domain.normalization.standard.model.enums;

import com.sh.data.engine.domain.common.model.domain.KeyValueDomain;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author boyue.wjl
 */
public enum DataTypeEnum {
    STRING("string", "字符型"),
    NUMBER("number", "数字型"),
    DATE("date", "日期型"),
    DATETIME("datetime", "日期时间型"),
    ;

    private String val;
    private String des;

    private DataTypeEnum(String val, String des) {
        this.val = val;
        this.des = des;
    }

    public static List<KeyValueDomain> getKeyValueList() {
        List<KeyValueDomain> resultList = new ArrayList<>();
        for (DataTypeEnum dataTypeEnum : values()) {
            KeyValueDomain domain = new KeyValueDomain();
            domain.setKey(dataTypeEnum.getVal());
            domain.setValue(dataTypeEnum.getDes());
            resultList.add(domain);
        }
        return resultList;
    }

    public static DataTypeEnum valueOfDes(String des) {
        for (DataTypeEnum dataTypeEnum : values()) {
            if (Objects.equals(des, dataTypeEnum.getDes())) {
                return dataTypeEnum;
            }
        }
        return null;
    }

    public static String toStringByVal(String val) {
        if (StringUtils.isBlank(val)) {
            return "";
        }
        for (DataTypeEnum dataTypeEnum : values()) {
            if (Objects.equals(dataTypeEnum.getVal(), val)) {
                return dataTypeEnum.getDes() + "(" + dataTypeEnum.getVal() + ")";
            }
        }
        return "";
    }

    public String getVal() {
        return val;
    }

    public String getDes() {
        return des;
    }
}
